home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / LIBRARY.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  10KB  |  543 lines

  1. #include "pt.h"
  2. #include "conio.h"
  3.  
  4. extern union REGS rin, rout;
  5. extern struct SREGS segRegs;
  6. extern unsigned char msgBuffer[];
  7.  
  8. int pascal CommandToMenuNumber( command )
  9.     int command;
  10. {
  11.     int ret;
  12.  
  13.     switch( command ) {
  14.         default:      ret = 0;  break;
  15.         case FMENU1:  ret = 1;  break;
  16.         case FMENU2:  ret = 2;  break;
  17.         case FMENU3:  ret = 3;  break;
  18.         case FMENU4:  ret = 4;  break;
  19.         case FMENU5:  ret = 5;  break;
  20.         case FMENU6:  ret = 6;  break;
  21.         case FMENU7:  ret = 7;  break;
  22.         case FMENU8:  ret = 8;  break;
  23.         case FMENU9:  ret = 9;  break;
  24.         case FMENU10: ret = 10; break;
  25.         case FMENU11: ret = 11; break;
  26.         case FMENU12: ret = 12; break;
  27.         case FMENU13: ret = 13; break;
  28.         case FMENU14: ret = 14; break;
  29.         case FMENU15: ret = 15; break;
  30.         case FMENU16: ret = 16; break;
  31.     }
  32.     return ret;
  33. }
  34.  
  35. int pascal
  36. /* XTAG:FindMenuItem */
  37. FindMenuItem( menuNumber, menuCol )
  38.     int menuNumber, menuCol;
  39. {
  40.     extern struct menuBlock far *menus[];
  41.  
  42.     int i, n, col1;
  43.  
  44.     /* figure out which command it is */
  45.     n = menus[menuNumber]->nItems;
  46.     col1 = 0;
  47.     for(i = 1; i < (n-1); i++) {
  48.         col1 += farStrlen(menus[menuNumber]->cmdName[i]);
  49.         if( col1 > menuCol )
  50.             break;
  51.     }
  52.     return menus[menuNumber]->cmdNumber[i];
  53. }
  54.  
  55. int pascal
  56. /* XTAG:GetTime */
  57. GetTime()
  58. {
  59.     rin.h.ah = 0x2C;
  60.     intdos(&rin, &rout);
  61.     return (rout.h.dh * 100) + rout.h.dl;
  62. }
  63.  
  64. int pascal
  65. /* XTAG:farStrlen */
  66. farStrlen(fp)
  67.     register unsigned char far *fp;
  68. {
  69.     register int len;
  70.  
  71.     len = 0;
  72.     while( *fp++ != '\0' )
  73.         ++len;
  74.     return len;
  75. }
  76.  
  77. unsigned char * pascal
  78. /* XTAG:farString */
  79. farString(fp)
  80.     unsigned char far *fp;
  81. {
  82.     unsigned char *p;
  83.     static char buffer[120];
  84.  
  85.     p = &buffer[0];
  86.     while( (*p++ = *fp++) != '\0' )
  87.         ;
  88.     return &buffer[0];
  89. }
  90.  
  91. void pascal
  92. /* XTAG:waitForEvent */
  93. waitForEvent()
  94. {
  95.     extern struct event events[];
  96.  
  97.     register unsigned char *p;
  98.     register int evhead;
  99.  
  100.     while( 1 ) {
  101.         if( isKeystroke() ) {
  102.             (void)getKeystroke(p);
  103.             break;
  104.         }
  105.         if( isMouseEvent(0) ) {
  106.             evhead = getMouseEvent();
  107.             if( events[evhead].buttons != 0 )
  108.                 break;
  109.         }
  110.     }
  111. }
  112.  
  113. unsigned char pascal
  114. /* XTAG:getDefaultDrive */
  115. getDefaultDrive()
  116. {
  117.     rin.h.ah = 0x19;
  118.     intdos(&rin, &rout);
  119.     return rout.h.al;
  120. }
  121.  
  122. int pascal
  123. /* XTAG:setDefaultDrive */
  124. setDefaultDrive(driveNumber)
  125.     int driveNumber;
  126. {
  127.     rin.h.ah = 0xE;
  128.     rin.h.dl = (char)driveNumber;
  129.     intdos(&rin, &rout);
  130.     /* return the number of physical drives */
  131.     return rout.h.al;
  132. }
  133.  
  134. int pascal
  135. /* XTAG:isKeystroke */
  136. isKeystroke()
  137. {
  138.     extern int macroState;
  139.     extern int macroIndex;
  140.     extern int macroSize;
  141.  
  142.     if( macroState == 2 ) {
  143.         /* are there still characters in the macro? */
  144.         if ( macroIndex < macroSize )
  145.             return 1;
  146.         macroState = 0;
  147.     }
  148.     return kbhit();
  149. }
  150.  
  151. unsigned char pascal
  152. /* XTAG:getKeystroke */
  153. getKeystroke(p)
  154.     unsigned char *p;
  155. {
  156.     extern unsigned char textBuffer[];
  157.     extern int scrRows, scrCols;
  158.     extern int macroIndex;
  159.     extern int macroSize;
  160.     extern int macroState;
  161.     extern unsigned char macroText[];
  162.     extern int debug;
  163.  
  164.     register unsigned char ch1, ch2;
  165.  
  166.     /* are we playing back a macro? */
  167.     if( macroState == 2 ) {
  168.         if( macroIndex < macroSize ) {
  169.             ch2 = macroText[macroIndex++];
  170.             ch1 = macroText[macroIndex++];
  171.             *p = ch2;
  172.             return ch1;
  173.         }
  174.         macroState = 0;
  175.     }
  176.     /* else get one from the keyboard */
  177.     rin.h.ah = 0;
  178.     int86(0x16, &rin, &rout);
  179.     ch1 = rout.h.al;
  180.     ch2 = rout.h.ah;
  181.     if( macroState == 1 ) {
  182.         if( macroIndex < 100 ) {
  183.             macroText[macroIndex++] = ch2;
  184.             macroText[macroIndex++] = ch1;
  185.         } else {
  186.             macroState = 0;
  187.             macroSize = macroIndex;
  188.             msg("Macro overflow. Keystroke not recorded.", 3);
  189.             msg("", 0);    /* erase the sticky message */
  190.             msg("End recording keystrokes", 1);
  191.         }
  192.     }
  193.     *p = ch2;
  194.     return ch1;
  195. }
  196.  
  197. unsigned char pascal
  198. /* XTAG:incon */
  199. incon()
  200. {
  201.     unsigned char dummy;
  202.     
  203.     return getKeystroke(&dummy);
  204. }
  205.  
  206. unsigned char pascal
  207. /* XTAG:inconkb */
  208. inconkb()
  209. {
  210.     rin.h.ah = 0;
  211.     int86(0x16, &rin, &rout);
  212.     return (unsigned char)rout.h.al;
  213. }
  214.  
  215. unsigned char pascal
  216. /* XTAG:peekKeystroke */
  217. peekKeystroke(scan)
  218.     unsigned char *scan;
  219. {
  220.     extern int macroIndex;
  221.     extern int macroSize;
  222.     extern int macroState;
  223.     extern int debug;
  224.     extern unsigned char macroText[];
  225.  
  226.     /* are we playing back a macro? */
  227.     if( macroState == 2 ) {
  228.         if( macroIndex < macroSize ) {
  229.             /* return the char (not the scan code) */
  230.             /* that will be read on the next getKeystroke */
  231.             return macroText[macroIndex+1];
  232.         }
  233.         /* else */
  234.         macroState = 0;
  235.     }
  236.     rin.h.ah = 1;
  237.     int86(0x16, &rin, &rout);
  238.     *scan = (unsigned char)rout.h.ah;
  239.     return (unsigned char)rout.h.al;
  240. }
  241.  
  242. long pascal
  243. /* XTAG:lseekls */
  244. lseekls(handle, offset, method)
  245.     int handle, method;
  246.     long offset;
  247. {
  248.     long l;
  249.  
  250.     rin.h.ah = 0x42;
  251.     rin.h.al = (char)method;
  252.     rin.x.bx = handle;
  253.     rin.x.cx = (unsigned)(offset>>16);
  254.     rin.x.dx = (unsigned)offset;
  255.     intdos(&rin, &rout) & 0x1;
  256.     if( rout.x.cflag & 0x1 ) {
  257.         return (long)(-rout.x.ax);
  258.     } else {
  259.         l = (long)(unsigned)rout.x.dx;
  260.         l = (l<<16) + (long)(unsigned)rout.x.ax;
  261.         return l;
  262.     }
  263. }
  264.  
  265. void pascal
  266. /* XTAG:setvect */
  267. setvect(vectorNumber, segment, offset)
  268.     int vectorNumber, segment, offset;
  269. {
  270.     int saveDS;
  271.     
  272.     rin.h.ah = 0x25;
  273.     rin.h.al = (char)vectorNumber;
  274.     rin.x.dx = offset;
  275.     saveDS = segRegs.ds;
  276.     segRegs.ds = segment;
  277.     intdosx(&rin, &rout, &segRegs);
  278.     segRegs.ds = saveDS;
  279. }
  280.  
  281. void pascal
  282. /* XTAG:flush */
  283. flush()
  284. {
  285.     unsigned char dummy;
  286.  
  287.     while( 1 ) {
  288.         /* quit if there is no character waiting to be read */
  289.         if( !kbhit() )
  290.             break;
  291.         /* quit if the character waiting to be read is not a */
  292.         /* backspace*/
  293.         if( peekKeystroke(&dummy) != '\b')
  294.             break;
  295.         incon();    /* read and ignore the backspace */
  296.     }
  297. }
  298.  
  299. void pascal
  300. /* XTAG:scrollUp */
  301. scrollUp(nLines, row1, col1, row2, col2, attr)
  302.     int nLines, row1, col1, row2, col2, attr;
  303. {
  304.     rin.h.ah = 6;    /* scroll up */
  305.     rin.h.al = (char)nLines;
  306.     rin.h.bh = (char)attr;
  307.     rin.h.bl = 0;
  308.     rin.h.ch = (char)row1;
  309.     rin.h.cl = (char)col1;
  310.     rin.h.dh = (char)row2;
  311.     rin.h.dl = (char)col2;
  312.     int86(0x10, &rin, &rout);
  313. }
  314.  
  315. int pascal
  316. /* XTAG:allmemls */
  317. allmemls(size, maxPara)
  318.     unsigned int size;
  319.     int *maxPara;
  320. {
  321.     rin.h.ah = 0x48;
  322.     rin.x.bx = (int)size;
  323.     intdos(&rin, &rout);
  324.     if( rout.x.cflag & 1 )
  325.         *maxPara = rout.x.bx;
  326.     else
  327.         *maxPara = -1;
  328.     return rout.x.ax;
  329. }
  330.  
  331. int pascal
  332. /* XTAG:freemem */
  333. freemem(para)
  334.     int para;
  335. {
  336.     register int ret;
  337.     int saveES;
  338.  
  339.     if( para == 0 )
  340.         return 0;
  341.     rin.h.ah = 0x49;
  342.     saveES = segRegs.es;
  343.     segRegs.es = para;
  344.     intdosx(&rin, &rout, &segRegs);
  345.     if( rout.x.cflag & 1 )
  346.         ret = rout.x.ax;
  347.     else
  348.         ret = 0;
  349.     segRegs.es = saveES;
  350.     return ret;
  351. }
  352.  
  353. int pascal
  354. /* XTAG:renamels */
  355. renamels(oldName, newName)
  356.     unsigned char *oldName, *newName;
  357. {
  358.     rin.h.ah = 0x56;
  359.     rin.x.dx = (int)oldName;
  360.     rin.x.di = (int)newName;
  361.     intdosx(&rin, &rout, &segRegs);
  362.     if( rout.x.cflag & 1 )
  363.         return rout.x.ax;
  364.     else
  365.         return 0;
  366. }
  367.  
  368. int pascal
  369. /* XTAG:creatls */
  370. creatls(name, attr)
  371.     unsigned char *name;
  372.     int attr;
  373. {
  374.     rin.h.ah = 0x3C;    /* create file */
  375.     rin.x.cx = attr;
  376.     rin.x.dx = (int)name;
  377.     intdos(&rin, &rout);
  378.     if( rout.x.cflag & 0x1 )
  379.         return -rout.x.ax;
  380.     else
  381.         return rout.x.ax;
  382. }
  383.  
  384. int pascal
  385. /* XTAG:openls */
  386. openls(name, attr)
  387.     unsigned char *name;
  388.     int attr;
  389. {
  390.     rin.h.ah = 0x3D;    /* open file */
  391.     rin.h.al = (char)attr;
  392.     rin.x.dx = (int)name;
  393.     intdos(&rin, &rout);
  394.     if( rout.x.cflag & 0x1 )
  395.         return -rout.x.ax;
  396.     else
  397.         return rout.x.ax;
  398. }
  399.  
  400. int pascal
  401. /* XTAG:closels */
  402. closels(handle)
  403.     int handle;
  404. {
  405.     rin.h.ah = 0x3E;
  406.     rin.x.bx = handle;
  407.     intdos(&rin, &rout);
  408.     if( rout.x.cflag & 0x1 )
  409.         return rout.x.ax;
  410.     else
  411.         return 0;
  412. }
  413.  
  414. int pascal
  415. /* XTAG:readls */
  416. readls(handle, buffer, nBytes)
  417.     int handle, nBytes;
  418.     unsigned char *buffer;
  419. {
  420.     rin.h.ah = 0x3F;
  421.     rin.x.bx = handle;
  422.     rin.x.cx = nBytes;
  423.     rin.x.dx = (int)buffer;
  424.     intdos(&rin, &rout);
  425.     if( rout.x.cflag & 0x1 )
  426.         return -rout.x.ax;
  427.     else
  428.         return rout.x.ax;
  429. }
  430.  
  431. int pascal
  432. /* XTAG:readFar */
  433. readFar(handle, buffer, nBytes)
  434.